<?php
include "includes/global.php";
$xtpl = new XTemplate ("themes/".theme."/index.htm");

include "includes/function.php";
include "includes/function_layout.php";


/*******************************************************/
if($_GET['lang']=='v'){
	WRITE_SESSION("LANG", $_GET['lang']);
}else if($_GET['lang']=='e'){
	WRITE_SESSION("LANG", "e");
}else{
	if(!READ_SESSION("LANG")){
		WRITE_SESSION("LANG", "e");
	}
}
$lang=READ_SESSION("LANG");

include "includes/setting.php";

define("lang", $lang);
$xtpl->assign("lang", $lang);

if($lang=='v'){
	include "lang/vietnamese.php";
	$xtpl->assign("change_lang", "e");
	$xtpl->assign("language", English);
	
	
	$mod_destination = 'diem-den';
	$mod_tour = 'tours';
	$mod_hotel = 'khach-san';
	$mod_otherservice = 'dich-vu-khac';
	$mod_daytrip = 'tour-trong-ngay';
	$mod_aboutus = 'gioi-thieu';
	$mod_contact = 'lien-he';
	$mod_review = 'nhan-xet-cua-khach-hang';
	$mod_news = 'tin-tuc';
	$mod_travelstyle = 'loai-hinh-du-lich';
	$mod_search = 'tim-kiem';
	$mod_booktour = 'dat-tour';
	$mod_booktoursuccess = 'dat-tour-thanh-cong';
	$mod_bookhotel = 'dat-khach-san';
	$mod_bookhotelsuccess = 'dat-khach-san-thanh-cong';
	$mod_bookdaytrip = 'dat-tour-ngay';
	$mod_bookdaytripsuccess = 'dat-daytrip-thanh-cong';
}else{
	include "lang/english.php";

	$xtpl->assign("change_lang", "v");
	$xtpl->assign("language", Vietnamese);

	$mod_destination = 'destinations';
	$mod_tour = 'tours';
	$mod_hotel = 'hotels';
	$mod_otherservice = 'otherservices';
	$mod_daytrip = 'daytrips';
	$mod_aboutus = 'aboutus';
	$mod_contact = 'contact';
	$mod_review = 'review';
	$mod_news = 'news';
	$mod_travelstyle = 'travelstyles';
	$mod_search = 'search';
	$mod_booktour = 'book-tour';
	$mod_booktoursuccess = 'book-tour-success';
	$mod_bookhotel = 'book-hotel';	
	$mod_bookhotelsuccess = 'book-hotel-success';
	$mod_bookdaytrip = 'book-daytrip';
	$mod_bookdaytripsuccess = 'book-daytrip-success';
}

// module
$xtpl->assign("mod_destination", $mod_destination);
$xtpl->assign("mod_tour", $mod_tour);
$xtpl->assign("mod_hotel", $mod_hotel);
$xtpl->assign("mod_otherservice", $mod_otherservice);
$xtpl->assign("mod_daytrip", $mod_daytrip);
$xtpl->assign("mod_aboutus", $mod_aboutus);
$xtpl->assign("mod_contact", $mod_contact);
$xtpl->assign("mod_review", $mod_review);
$xtpl->assign("mod_news", $mod_news);
$xtpl->assign("mod_travelstyle", $mod_travelstyle);
$xtpl->assign("mod_search", $mod_search);	

// lbl
$xtpl->assign("lbl_home", Home);
$xtpl->assign("lbl_destination", Destination);
$xtpl->assign("lbl_tour", Tour);
$xtpl->assign("lbl_hotel", Hotel);
$xtpl->assign("lbl_otherservice", OtherService);
$xtpl->assign("lbl_daytrip", Daytrip);

$xtpl->assign("lbl_country", Country);
$xtpl->assign("lbl_travelstyle", TravelStyle);
$xtpl->assign("lbl_city", City);
$xtpl->assign("lbl_lengthofstay", LengthOfStay);
$xtpl->assign("lbl_star", Star);




$xtpl->assign("lbl_contact", Contact);
$xtpl->assign("lbl_aboutus", Aboutus);

$xtpl->assign("lbl_search", Search);
$xtpl->assign("lbl_keyword", Keyword);
$xtpl->assign("lbl_select", Select);

$xtpl->assign("Address", Address);
$xtpl->assign("Phone", Phone);
$xtpl->assign("PowerBy", PowerBy);

//////////////////////////////////////////////////////////
define('site_name', '<img src="{const_Web_Url}themes/'.theme.'/images/home.gif" border="0" align="bottom" />&nbsp;<a href="'.const_Web_Url.'" class="path">'.Home.'</a>');

$xtpl->assign("bg_top", "background: url(".const_Web_Url."themes/".theme."/images/bg_top.jpg) top center no-repeat fixed;");
if($configuration_bghome){
	$xtpl->assign("bg_top", "background: url(".const_Web_Url."media/logo/".$configuration_bghome.") top center no-repeat fixed;");
}
/*******************************************************/
$mod = $arrPath[1];

if($mod==$mod_destination){
	$xtpl->assign("active_destinations", "_active");
	
	if($configuration_bgdestination){
		$xtpl->assign("bg_top", "background: url(".const_Web_Url."media/logo/".$configuration_bgdestination.") top center no-repeat fixed;");
	}
}else if($mod==$mod_tour){
	$xtpl->assign("active_tours", "_active");
	
	if($configuration_bgtour){
		$xtpl->assign("bg_top", "background: url(".const_Web_Url."media/logo/".$configuration_bgtour.") top center no-repeat fixed;");
	}
}else if($mod==$mod_hotel){
	$xtpl->assign("active_hotels", "_active");

	if($configuration_bghotel){
		$xtpl->assign("bg_top", "background: url(".const_Web_Url."media/logo/".$configuration_bghotel.") top center no-repeat fixed;");
	}	
}else if($mod==$mod_otherservice){
	$xtpl->assign("active_otherservices", "_active");
	
	if($configuration_bgother){
		$xtpl->assign("bg_top", "background: url(".const_Web_Url."media/logo/".$configuration_bgother.") top center no-repeat fixed;");
	}
}else if($mod==$mod_daytrip){
	$xtpl->assign("active_daytrips", "_active");
	
	if($configuration_bgdaytrip){
		$xtpl->assign("bg_top", "background: url(".const_Web_Url."media/logo/".$configuration_bgdaytrip.") top center no-repeat fixed;");
	}
	
}


$cond = " AND lang='".$lang."'";

$country_code = $arrPath[2];
$country_array = getCountryID($country_code);
$country_id = intval($country_array[0]);

// search
$tabsearch = $_GET['tabsearch'];
$xtpl->assign("tabsearch", $tabsearch);

// ++ length of stay
$lengthofstay_tour = intval($_GET['lengthofstay_tour']);
$xtpl->assign('cbo_lengthofstay', cbo_lengthofstay($lengthofstay_tour));
// -- length of stay

// ++ country 
if($_GET['country_tour']){
	$country_id = intval($_GET['country_tour']);
}else if($_GET['country_hotel']){
	$country_id = intval($_GET['country_hotel']);
}else if($_GET['country_daytrip']){
	$country_id = intval($_GET['country_daytrip']);
}


$mod_country = "tours";
if(in_array($mod, array($mod_destination, $mod_tour, $mod_hotel, $mod_otherservice, $mod_daytrip, $mod_travelstyle))){
	$mod_country = $mod;
}
$xtpl->assign("mod_country", $mod_country);	

if($mod==$mod_daytrip){
	$cond_daytrip .= " AND country_code<>'multi-country'";
}
$sql_country = "SELECT country_id, country_name, country_code FROM ".pre_table."country
				WHERE country_isactive=1 ".$cond.$cond_daytrip." 
				ORDER BY country_position";
$rs_country = execSQL($sql_country);
if(mysql_num_rows($rs_country)>0){
	while($row_country = mysql_fetch_array($rs_country)){
		if($row_country['country_id']==$country_id){
			$select=" selected='selected'";
		}else {
			$select="";
		}
		$cbo_country.="<option value='".$row_country['country_id']."' ".$select.">".$row_country['country_name']."</option>";
		
		$xtpl->assign("country", $row_country);	
		$xtpl->parse("MAIN.COUNTRY");
	}		

			
}
$xtpl->assign('cbo_country', $cbo_country);
// -- country 

// ++ city
if($_GET['city_daytrip']){
	$city_id = intval($_GET['city_daytrip']);
}else if($_GET['city_hotel']){
	$city_id = intval($_GET['city_hotel']);
}
$xtpl->assign('cbo_city', cbo_city($country_id, $city_id));

// -- city

// ++ travelstyle 
if($_GET['travelstyle_tour']){
	$travelstyle_id = intval($_GET['travelstyle_tour']);
}else if($_GET['travelstyle_daytrip']){
	$travelstyle_id = intval($_GET['travelstyle_daytrip']);
}

if($country_id){
	$xtpl->assign('country_code', $country_array[2].'/');
	
	$cond .= " AND ct.country_id = '".$country_id."'";
	$sql_travelstyle = "SELECT t.travelstyle_id, t.travelstyle_name FROM ".pre_table."travelstyle t, ".pre_table."country_travelstyle ct
				WHERE t.travelstyle_id=ct.travelstyle_id AND t.travelstyle_isactive=1 ".$cond." 
				ORDER BY t.travelstyle_position";
}else{
	$sql_travelstyle = "SELECT t.travelstyle_id, t.travelstyle_name FROM ".pre_table."travelstyle t
				WHERE t.travelstyle_isactive=1 ".$cond." 
				ORDER BY t.travelstyle_position";
}

$rs_travelstyle = execSQL($sql_travelstyle);
if(mysql_num_rows($rs_travelstyle)>0){
	while($row_travelstyle = mysql_fetch_array($rs_travelstyle)){
		$row_travelstyle['TravelstyleName'] = codau2kodau($row_travelstyle['travelstyle_name']);
		
		if($row_travelstyle['travelstyle_id']==$travelstyle_id){
			$select=" selected='selected'";
		}else {
			$select="";
		}
		$cbo_travelstyle.="<option value='".$row_travelstyle['travelstyle_id']."' ".$select.">".$row_travelstyle['travelstyle_name']."</option>";
		
		$xtpl->assign("travelstyle",$row_travelstyle);	
		$xtpl->parse("MAIN.TRAVELSTYLE");
	}				
}
$xtpl->assign('cbo_travelstyle', $cbo_travelstyle);

//$xtpl->assign('show_travelstyle', showTravelstyle($country_id));
// -- travelstyle 

// ++ star
$star_hotel = intval($_GET['star_hotel']);
$xtpl->assign('cbo_star', cbo_star($star_hotel));
// -- star


// ++ left

$xtpl->assign('show_review', showReview());
$xtpl->assign('show_news', showNews());
$xtpl->assign('show_faq', showFaq());
$xtpl->assign('show_logo', showLogo());
// -- left

switch ($mod) {	
	
	case $mod_news:
		$news_id = intval($arrPath[2]);	
		$xtpl->assign("show_content", showNewsDetail($news_id));
		
		$site_title = News;
		$site_path = site_name.' &raquo; '.News;
		
		break;
		
	case $mod_aboutus:
		if($mod=='aboutus'){
			$other_id = 3;
		}else if($mod=='gioi-thieu'){
			$other_id = 5;
		
		}
		
		$xtpl->assign("show_content", showOther($other_id));
		
		$site_title = Aboutus;
		$site_path = site_name.' &raquo; '.Aboutus;

		break;
	
	case $mod_destination:
		$destination_id = intval($arrPath[2]);		
			
		if($destination_id){
			$xtpl->assign("show_content", showDestinationDetail($destination_id));
		}else{
			$xtpl->assign("show_content", showDestination());
		}

		
		$site_title = Destination;
		$site_path = site_name.' &raquo; '.'<a href="'.const_Web_Url.'index.php/'.$mod_destination.'" class="path">'.Destination.'</a>'.$country_name;
		
		break;
		
	case $mod_tour:
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}

		
		$tour_id = intval($arrPath[3]);
		
			
		if($tour_id){
			$xtpl->assign("show_content", showTourDetail($country_id, $tour_id));
		}else{
			$xtpl->assign("show_content", showTour($country_id));
		}
		
		$site_title = Tour.' - '.$title;
		$site_path = site_name.' &raquo; '.'<a href="'.const_Web_Url.'index.php/'.$mod_tour.'" class="path">'.Tour.'</a>'.$country_name;
				
		break;
	
	case $mod_hotel:
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}
		
		$hotel_id = intval($arrPath[3]);
		
			
		if($hotel_id){
			$xtpl->assign("show_content", showHotelDetail($country_id, $hotel_id));
		}else{
			$xtpl->assign("show_content", showHotel($country_id));
		}
		
		$site_title = Hotel.' - '.$title;		
		$site_path = site_name.' &raquo; '.'<a href="'.const_Web_Url.'index.php/'.$mod_hotel.'" class="path">'.Hotel.'</a>'.$country_name;
		
		break;			

	case $mod_daytrip:
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}
		
		$daytrip_id = intval($arrPath[3]);
		
			
		if($daytrip_id){
			$xtpl->assign("show_content", showDaytripDetail($country_id, $daytrip_id));
		}else{
			$xtpl->assign("show_content", showDaytrip($country_id));
		}
		
		$site_title = Daytrip.' - '.$title;		
		$site_path = site_name.' &raquo; '.'<a href="'.const_Web_Url.'index.php/'.$mod_daytrip.'" class="path">'.Daytrip.'</a>'.$country_name;
		
		break;	
	
	case $mod_otherservice:
		$xtpl->assign("show_content", showOtherService());
		
		$site_title = OtherService;		
		$site_path = site_name.' &raquo; '.'<a href="'.const_Web_Url.'index.php/'.$mod_otherservice.'" class="path">'.OtherService.'</a>';
		
		break;
	
	case $mod_travelstyle:
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}
		
		if(is_numeric($arrPath[2])){
			$travelstyle_id = intval($arrPath[2]);
		}else{
			$travelstyle_id = intval($arrPath[3]);
		}
		
			
		if($travelstyle_id){
			$sql = "SELECT travelstyle_name, travelstyle_brief FROM ".pre_table."travelstyle
					WHERE travelstyle_id='".$travelstyle_id."' AND lang='".$lang."'";
			$rs = recordset($sql);
			$travelstyle_name = ' &raquo; <a href="'.const_Web_Url.'index.php/'.$mod_travelstyle.'/'.$country_code.'/'.$travelstyle_id.'/'.codau2kodau($rs['travelstyle_name']).'" class="path">'.$rs['travelstyle_name'].'</a>';
			$travelstyle_brief = $rs['travelstyle_brief'];
	
			$xtpl->assign("show_content", showTravelstyleDetail($country_id, $travelstyle_id));
		}
		
		$site_title = Travelstyle;		
		$site_path = site_name.' &raquo; '.Travelstyle.$travelstyle_name.$country_name;
		
		break;	
			
	case $mod_review:
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}
	
		$xtpl->assign("show_content", showReviewDetail($country_id));
		
		$site_title = Review;		
		$site_path = site_name.' &raquo; '.'<a href="'.const_Web_Url.'index.php/'.$mod_review.'" class="path">'.Review.'</a>'.$country_name;
		
		break;
		
	case 'faqs':
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}
	
		$xtpl->assign("show_content", showFaqDetail($country_id));
		
		$site_title = Faq;
		$site_path = site_name.' &raquo; '.Faq.$country_name;
		
		break;
			
	case $mod_contact:
	case 'contact-success':
	case 'lien-he-thanh-cong':
		if($mod=='lien-he-thanh-cong' || $mod=='contact-success'){
			$sent = 1;
		}
		
		$xtpl->assign("show_content", showContact($sent));
		
		$site_title = Contact;
		$site_path = site_name.' &raquo; '.Contact;
		
		break;	
		
	case $mod_booktour:
	case $mod_booktoursuccess:
		$tour_id = intval($arrPath[2]);
		
		if($mod==$mod_booktoursuccess){
			$sent = 1;
		}
		
		$xtpl->assign("show_content", showBookTour($sent, $tour_id));
		
		$site_title = BookTour;
		$site_path = site_name.' &raquo; '.BookTour;
		
		break;
	
	case $mod_bookdaytrip:
	case $mod_bookdaytripsuccess:
		$daytrip_id = intval($arrPath[2]);
		
		if($mod==$mod_bookdaytripsuccess){
			$sent = 1;
		}
		
		$xtpl->assign("show_content", showBookDaytrip($sent, $daytrip_id));
		
		$site_title = BookDaytrip;
		$site_path = site_name.' &raquo; '.BookDaytrip;
		
		break;	
		
	case $mod_bookhotel:
	case $mod_bookhotelsuccess:
		$hotel_id = intval($arrPath[2]);
		
		if($mod==$mod_bookhotelsuccess){
			$sent = 1;
		}
		
		$xtpl->assign("show_content", showBookHotel($sent, $hotel_id));
		
		$site_title = BookHotel;
		$site_path = site_name.' &raquo; '.BookHotel;
		
		break;	
	
	case $mod_search:
		if($tabsearch=='hotel'){
			$keyword_hotel = formatData($_GET['keyword_hotel']);
			$country_hotel = intval($_GET['country_hotel']);
			$city_hotel = intval($_GET['city_hotel']);
			
			$xtpl->assign("keyword_hotel", $keyword_hotel);

			$xtpl->assign("show_content", showSearchResultHotel($keyword_hotel, $country_hotel, $city_hotel));	
		}else if($tabsearch=='daytrip'){
			$keyword_daytrip = formatData($_GET['keyword_daytrip']);
			$country_daytrip = intval($_GET['country_daytrip']);
			$city_daytrip = intval($_GET['city_daytrip']);
			$travelstyle_daytrip = intval($_GET['travelstyle_daytrip']);
			
			$xtpl->assign("keyword_daytrip", $keyword_daytrip);
			
			$xtpl->assign("show_content", showSearchResultDaytrip($keyword_daytrip, $country_daytrip, $city_daytrip, $travelstyle_daytrip));	
		}else{
			$keyword_tour = formatData($_GET['keyword_tour']);
			$country_tour = intval($_GET['country_tour']);
			$travelstyle_tour = intval($_GET['travelstyle_tour']);
			
			$xtpl->assign("keyword_tour", $keyword_tour);
			
			$xtpl->assign("show_content", showSearchResultTour($keyword_tour, $country_tour, $travelstyle_tour));	
		}
	
		
		
		$site_title = SearchResult;
		$site_path = site_name.' &raquo; '.Search;
		
		break;
			
	default:
		if($country_array[1]){
			$country_name = ' &raquo; '.$country_array[1];
		}	
	
			
		$xtpl->assign("show_tourhome", showTourHome($country_id, 1));
		$xtpl->assign("show_hotelhome", '<div style="clear:both;"><br /></div>'.showHotelHome($country_id, 1));

		$site_title = Home;
		$site_path = site_name;

		//$xtpl->assign("path_css", "#path{color:#FF7700;height:5px;}");

		break;
		
}
//if($mod) $xtpl->assign("left_css", " style='padding-top:25px;'");

$xtpl->assign('site_title', $site_title);
$xtpl->assign("site_path", $site_path);
		
// ++ slide show
$arr_tab = array("home", "destinations", "tours", "hotels", "otherservices", "daytrips");
$tab = 'home';
if(in_array($mod, $arr_tab)){
	$tab = $mod;
}
$xtpl->assign('show_slideshow', showSlideshow($country_id, $tab));
// -- slide show

// ++ meta
if($metadescription) $xtpl->assign('metadescription', $metadescription);
if($metakeyword) $xtpl->assign('metakeyword', $metakeyword);
// -- meta

$xtpl->assign('show_utility_currency', showUtilityCurrency());
$xtpl->assign('show_utility_weather', showUtilityWeather());



/*******************************************************/
$xtpl->parse("MAIN");	
$xtpl->out("MAIN");			
?>